/**
 * Created with IntelliJ IDEA.
 * User: guangyu
 * Date: 3/11/13
 * Time: 2:01 PM
 * To change this template use File | Settings | File Templates.
 */

var ge = ge = ge || {};
(function () {
    /**
     * The base Class implementation (does nothing)
     * @class
     */
    var initializing = false, fnTest = /\b_super\b/;
    ge.Class = function () {
    };

    ge.Class.extend = function (prop) {

        var _super = this.prototype;

        // Instantiate a base Class (but only create the instance,
        // don't run the init constructor)
        initializing = true;
        var prototype = new this();
        initializing = false;

        function Class() {
            if (!initializing && this.ctor) {
                this.ctor.apply(this, arguments);
            }
        }//dummy class

        for (var name in prop) {
            if (typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name])) {
                prototype[name] = (function (name, fn) {
                    return function () {
                        var tmp = this._super;

                        // Add a new ._super() method that is the same method
                        // but on the super-Class
                        this._super = _super[name];

                        // The method only need to be bound temporarily, so we
                        // remove it when we're done executing
                        var ret = fn.apply(this, arguments);
                        this._super = tmp;

                        return ret;
                    };
                })(name, prop[name]);
            }
            else {
                prototype[name] = prop[name];
            }
        }
        Class.prototype = prototype;
        // And make this Class extendable
        Class.extend = arguments.callee;

        Class.prototype.constructor = Class;

        return Class;
    }


})();
/**
 * Create a new Class that inherits from this Class
 * @param {object} prop
 * @return {function}
 */
ge.inherits = function (Child, Parent) {
    if (Parent == undefined) {
        Parent = ge.Class;
    }
    var F = function () {
    };
    F.prototype = Parent.prototype;
    Child.prototype = new F();
    Child.prototype.constructor = Child;
    Child._super = Parent.prototype;
}